#include <unistd.h>
#include <cstdio>
#include <csignal>

/*
 * 信号处理函数
 */
void signal_handler(int sig) {
    printf("\nthis signal number is %d \n", sig);

    if (sig == SIGINT) {
        printf("I have get SIGINT!\n\n");
        printf("The signal has been restored to the default processing mode!\n\n");
        /** 恢复信号为默认情况 */
        signal(SIGINT, SIG_DFL);
    }

}

int main() {
    printf("\nthis is an singal test function\n\n");

    /** 设置信号处理的回调函数 */
    signal(SIGINT, signal_handler);

    while (1) {
        printf("waiting for the SIGINT signal , please enter \"ctrl + c\"...\n");
        sleep(1);
    }

    _exit(0);
}